<template>
    <div class="input-item">
      <el-form :model="deviceform" ref="deviceform" :rules="rules" label-width="250px">
          <div class="parameType-wrap">
              <div class="parameType">
                <div class="button">
                  <!-- <span>病毒检测规则</span> -->
                  <el-button style="float: right; padding:4px 8px;" type="primary" @click="operationClick('deviceform')">确定</el-button>
                </div>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="检测引擎：">
                    <!-- <el-checkbox-group v-model="deviceform.virus_engineer"> -->
                      <el-checkbox true-label='1' false-label='0' v-model="checkBoxOne">全球检测引擎</el-checkbox>
                      <el-checkbox true-label='1' false-label='0' v-model="checkBoxTwo">国产检测引擎</el-checkbox>
                      <el-checkbox true-label='1' false-label='0' v-model="checkBoxThree">开源检测引擎</el-checkbox>
                      <el-checkbox true-label='1' false-label='0' v-model="checkBoxFour">智能检测引擎</el-checkbox>
                    <!-- </el-checkbox-group> -->
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="检测文件最大尺寸：" prop="virus_scan_max_size">
                    <el-input class="input-style" v-model="deviceform.virus_scan_max_size "><span slot="append">M</span></el-input>
                    <span class="tips-style">（配为0代表无效）</span>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="只检测指定后缀文件：" prop="include_file_ext">
                    <el-input class="input-style" v-model="deviceform.include_file_ext "></el-input>
                    <span class="tips-style">（配为空代表无效）</span>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="排除指定后缀文件：" prop="exclude_file_ext">
                    <el-input class="input-style" v-model="deviceform.exclude_file_ext "></el-input>
                    <span class="tips-style">（配为空代表无效）</span>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="清理智能杀毒周期：" prop="clean_scan_history">
                    <el-input class="input-style" v-model="deviceform.clean_scan_history"><span slot="append">分</span></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="智能杀毒缓存条数：" prop="virus_scan_retain_max_total">
                    <el-input class="input-style" v-model="deviceform.virus_scan_retain_max_total"><span slot="append">条</span></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="智能杀毒时间权重：" prop="delscore_up_time_unit">
                    <el-input class="input-style" v-model="deviceform.delscore_up_time_unit"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="智能杀毒重复权重：" prop="delscore_down_freq_unit">
                    <el-input class="input-style" v-model="deviceform.delscore_down_freq_unit"></el-input>
                  </el-form-item>
                </el-col>
                <!-- <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="每天指定时间自动重启设备:">
                    <el-select v-model="deviceform.reset_on_hours" style="width:100%;">
                      <el-option :value='0' label="不控制"></el-option>
                      <el-option v-for="item in 23" :key="item" :label="item + ':00'" :value="item"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col> -->
                <el-col :xs="24" :sm="24" :lg="24">
                  <el-form-item label="进程自检喂狗周期：" prop="write_watch_dog_interval">
                    <el-input class="input-style" v-model="deviceform.write_watch_dog_interval"><span slot="append">秒</span></el-input>
                  </el-form-item>
                </el-col>
                
                
                
              </div>
          </div>    
      </el-form>
    </div>
</template>
  
<script>
import { connrequest } from '@/api/firstPage'
import { validNum } from '@/utils/validate'
export default {
    data() {
        return {
          checkBoxOne:'0',
          checkBoxTwo:'0',
          checkBoxThree:'0',
          checkBoxFour:'0',
          deviceform:{
            virus_engineer:[],
            virus_scan_max_size :'',
            include_file_ext:'',
            exclude_file_ext:'',
            page_length:0,
            clean_scan_history:0,
            virus_scan_retain_max_total:0,
            delscore_up_time_unit:0,
            delscore_down_freq_unit:0,
            write_watch_dog_interval:0
          },
          oldData:[],
          rules:{
            virus_scan_max_size:[{required:true,validator:validNum,trigger:'blur'}],
            clean_scan_history:[{required:true,validator:validNum,trigger:'blur'}],
            include_file_ext:[{required:true,message:'请输入只检测指定后缀文件',trigger:'blur'}],
            exclude_file_ext:[{required:true,message:'请输入排除指定后缀文件',trigger:'blur'}],
            virus_scan_retain_max_total:[{required:true,validator:validNum,trigger:'blur'}],
            delscore_down_freq_unit:[{required:true,validator:validNum,trigger:'blur'}],
            delscore_up_time_unit:[{required:true,validator:validNum,trigger:'blur'}],
            write_watch_dog_interval:[{required:true,validator:validNum,trigger:'blur'}]
          }
        }
    },
    created(){
    this.getData()
    // console.log();
    
    },
    methods:{
    // 
      async getData(){
          // const data = {}
          const res = await connrequest('GetParamThreshhold')
          // console.log(res.Data);
          this.oldData = res.Data;
          res.Data = res.Data.map(item => {
            for (const i in this.deviceform) {
                if (item.Name === i) {
                  this.deviceform[i] = item.Value
                }
            }
          })
          this.deviceform.virus_engineer = this.deviceform.virus_engineer.split('')
          this.checkBoxOne = this.deviceform.virus_engineer[0]
          this.checkBoxTwo = this.deviceform.virus_engineer[1]
          this.checkBoxThree = this.deviceform.virus_engineer[2]
          this.checkBoxFour = this.deviceform.virus_engineer[3]
      },
      async operationClick(formName){
        this.$refs[formName].validate(async(valid) => {
          if (valid) {
            this.deviceform.virus_engineer[0] = this.checkBoxOne
            this.deviceform.virus_engineer[1] = this.checkBoxTwo
            this.deviceform.virus_engineer[2] = this.checkBoxThree
            this.deviceform.virus_engineer[3] = this.checkBoxFour
            this.deviceform.virus_engineer = this.deviceform.virus_engineer.join('')
            this.oldData = this.oldData.map(item => {
            for (const key in this.deviceform) {
                if(item.Name === key){
                if (typeof this.deviceform[key] != 'string') {
                    item.Value = JSON.stringify(this.deviceform[key])
                }else{
                    item.Value = this.deviceform[key]
                }
                }
                }
                return item
            })
            const data = {
                Data:this.oldData
            }
            const res = await connrequest('SetParamThreshhold',data)
            this.$message.success('修改成功')
            this.getData();
          }
        })
      },
    // async operationClick(){
      
    //     this.deviceform.virus_engineer[0] = this.checkBoxOne
    //     this.deviceform.virus_engineer[1] = this.checkBoxTwo
    //     this.deviceform.virus_engineer[2] = this.checkBoxThree
    //     this.deviceform.virus_engineer[3] = this.checkBoxFour
    //     // 
    //     this.deviceform.virus_engineer = this.deviceform.virus_engineer.join('')
    //     // console.log(this.deviceform.virus_engineer);
    //     this.oldData = this.oldData.map(item => {
    //     for (const key in this.deviceform) {
    //         if(item.Name === key){
    //           item.Value = this.deviceform[key]
    //         }
    //     }
    //     return item
    //     })
    //     console.log(this.oldData);
    //     const data = {
    //       Data:this.oldData
    //     }
    //     const res = await connrequest('SetParamThreshhold',data)
    //     this.$message.success('修改成功')
    //     this.getData();
    // }
    }
}
</script>

<style lang="scss" scoped>
/* @import url(); 引入css类 */
.parameType-wrap{
    display:flex;
    flex-wrap: wrap;
}
::v-deep.input-item{
    // margin-top: 10px;
    .parameType{
    border: 1px solid #eceff5;
    border-radius: 3px;
    width: 800px;
    //   padding: 10px;
    margin: 0px;
    box-shadow: 0 0 10px #eceff5;
    .button{
        
        border-bottom: 1px solid #eceff5;
        padding-bottom : 32px;
    }
    }
    .el-form-item{
    margin-bottom: 6px;
    }
    .el-input-group__append, .el-input-group__prepend{
    width: 60px;
    padding: 0;
    text-align: center;
    }
}
.button{
    margin-bottom: 20px;
}
::v-deep.el-form-item{
    label{
    font-weight: 500;
    }
}
.input-style{
    width: 70% !important;
}
</style>